package com.itheima.domain;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;


//组件
@Component
//@Component("u")  不指定id默认为user
//component的衍生
//@Service
//@controller
//@Repository
@Scope
//从外部配置文件取值 存入ioc容器
//@PropertySource("classpath:db.properties")
public class User {

    //将外部配置文件存入ioc的值 注入username
   // @Value("${jdbc.username}")
    private String username;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Value("18") //代替set方法
    private int age;


   // 引用类型自动装配
    @Autowired
    //@Qualifier("address2")
    private Address address;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }


    //生命周期  出生
    @PostConstruct
    public void init(){}


    //生命周期销毁
    @PreDestroy

    public void init1(){}
}
